//package com.dz.tool.Config;
//
//import com.alibaba.druid.pool.DruidDataSource;
//import org.apache.ibatis.session.SqlSessionFactory;
//import org.mybatis.spring.SqlSessionFactoryBean;
//import org.mybatis.spring.SqlSessionTemplate;
//import org.mybatis.spring.annotation.MapperScan;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.beans.factory.annotation.Value;
//import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
//import org.springframework.jdbc.datasource.DataSourceTransactionManager;
//
//import javax.sql.DataSource;
//
////@Configuration
//// basePackages为oracle dao文件的路径，sqlSessionFactoryRef指定SqlSession工厂bean
////@MapperScan(basePackages = "com.dz.tool.Dao.Slave", sqlSessionFactoryRef = "slaveSqlSessionFactory")
//public class SlaveDataSourceConfig {
//    @Value("${spring.datasource.slave.url}")
//    private String url;
//
//    @Value("${spring.datasource.slave.username}")
//    private String user;
//
//    @Value("${spring.datasource.slave.password}")
//    private String password;
//
//    @Value("${spring.datasource.slave.driver-class-name}")
//    private String driverClass;
//
//    //对应oracle的mapper.xml文件路径
//    private static final String MAPPER_LOCATION = "classpath:mapper/Slave/*.xml";
//
//    /**
//     * 配置oracle DataSource
//     */
//    @Bean(name = "slaveDataSource")
//    public DataSource oracleDataSource() {
//        DruidDataSource dataSource = new DruidDataSource();
//        dataSource.setDriverClassName(driverClass);
//        dataSource.setUrl(url);
//        dataSource.setUsername(user);
//        dataSource.setPassword(password);
//        return dataSource;
//    }
//
//    /**
//     * 配置事务管理器
//     */
//    @Bean(name = "slaveTransactionManager")
//    public DataSourceTransactionManager oracleTransactionManager() {
//        return new DataSourceTransactionManager(oracleDataSource());
//    }
//
//    /**
//     * 配置SqlSession工厂
//     */
//    @Bean(name = "slaveSqlSessionFactory")
//    public SqlSessionFactory oracleSqlSessionFactory(@Qualifier("slaveDataSource") DataSource oracleDataSource)
//            throws Exception {
//        final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();
//        sessionFactory.setDataSource(oracleDataSource);
//        sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(SlaveDataSourceConfig.MAPPER_LOCATION));
//        return sessionFactory.getObject();
//    }
//
//    /**
//     * 配置SqlSessionTemplate
//     */
//    @Bean(name = "slaveSqlSessionTemplate")
//    public SqlSessionTemplate oracleSqlSessionTemplate(@Qualifier("slaveSqlSessionFactory") SqlSessionFactory sqlSessionFactory)
//            throws Exception {
//        return new SqlSessionTemplate(sqlSessionFactory);
//    }
//}
